﻿Class MainWindow
    Private Sub WebBrowser_Navigating_1(sender As Object, e As NavigatingCancelEventArgs)
        If Not IsNothing(ProgressBar1) Then ProgressBar1.IsIndeterminate = True
    End Sub

    Dim Server As String = ""
    Dim ServerKey As String = ""
    Dim ServerTS As String = ""
    Private Sub WebBrowser_LoadCompleted_1(sender As Object, e As NavigationEventArgs)
        If Not IsNothing(ProgressBar1) Then ProgressBar1.IsIndeterminate = False
        If InStr(e.Uri.AbsoluteUri, "access_token=") > 0 Then
            access_token = Split(Split(e.Uri.AbsoluteUri, "access_token=")(1), "&")(0)
            user_id = Split(e.Uri.AbsoluteUri, "user_id=")(1)
            My.Settings.access_token = access_token
            My.Settings.user_id = user_id
            My.Settings.Save()
            Me.Hide()
        End If
    End Sub

    Private Sub Window_Loaded_1(sender As Object, e As RoutedEventArgs)
        
        Dim a = New Popup
        a.Show()
        VkUpdate("Добро пожаловать!", "t")
    End Sub
    Async Sub LongPoll()
        If Server.Length > 0 Then
            Dim a = Await VKGet("http://" & Server & "?act=a_check&key=" & ServerKey & "&ts=" & ServerTS & "&wait=30&mode=2")
            ServerTS = a("ts").ToString
            VkUpdate(a.ToString, "test")
        Else
            Server = (Await VKPost("messages.getLongPollServer"))("server").ToString
            ServerKey = (Await VKPost("messages.getLongPollServer"))("key").ToString
            ServerTS = (Await VKPost("messages.getLongPollServer"))("ts").ToString
            LongPoll()
        End If

    End Sub
    Private Sub VkUpdate(Text As String, Title As String)
        
    End Sub

End Class
